﻿using System;
using System.Collections.Generic;
using System.Text;
using KPIS.DBM;
using System.Configuration;
using KPIS.GERP.GIMS.MODEL;
using System.Data;

namespace KPIS.GERP.GIMS.DAL
{
    public class D_SysRepairStatus
    {
        DBManager dbManager = new DBManager(DataProvider.MySQL, ConfigurationSettings.AppSettings["ConnectionString"].ToString());
        ConvertNullable cn = new ConvertNullable();

        public IList<M_SysRepairStatus> GetList()
        {
            string strSQL;
            DataRowCollection drc = null;
            IList<M_SysRepairStatus> infoList = new List<M_SysRepairStatus>();
            try
            {
                dbManager.Open();
                strSQL = " SELECT repair_status,status_name "
                        +" FROM icm_sys_repair_status "
                        +" ORDER BY repair_status DESC ";

                drc = dbManager.ExecuteDataSet(CommandType.Text, strSQL).Tables[0].Rows;
                if (drc.Count > 0)
                {
                    for (int i = 0; i < drc.Count; i++)
                    {
                        M_SysRepairStatus info = new M_SysRepairStatus();
                        info.repair_status = drc[i]["repair_status"].ToString();
                        info.status_name = drc[i]["status_name"].ToString();                       
                        infoList.Add(info);
                    }
                }
            }
            catch (Exception ex)
            {
                throw (ex);
            }
            finally
            {
                dbManager.Dispose();
            }

            return infoList;
        }
        public string GetListFillByName(string repair_name)
        {
            string strSQL;
            string status = "";
            DataRowCollection drc = null;
            M_SysRepairStatus info = new M_SysRepairStatus();
            try
            {
                dbManager.Open();

                strSQL =  "  SELECT repair_status,status_name  FROM icm_sys_repair_status "
                        + " WHERE status_name  LIKE '%' '" + repair_name + "'  '%' "
                        + " ORDER BY repair_status DESC ";

                drc = dbManager.ExecuteDataSet(CommandType.Text, strSQL).Tables[0].Rows;
                if (drc.Count > 0)
                {
                    status = drc[0]["repair_status"].ToString();
                }
            }
            catch (Exception ex)
            {
                throw (ex);
            }
            finally
            {
                dbManager.Dispose();
            }

            return status;
        }
    }
}
